package com.cavy.platform.server.domain.job;

import com.cavy.platform.server.domain.AgentOnline;
import com.cavy.platform.server.domain.SchedulingStrategy;

import java.util.Collection;

/**
 * @author 唐旭
 * @Date 2018/7/25
 */
public class LeastJobSelector implements JobDispatcher {
    @Override
    public boolean support(SchedulingStrategy schedulingStrategy) {
        return SchedulingStrategy.LEAST_JOB.equals(schedulingStrategy);
    }

    @Override
    public AgentOnline select(Collection<AgentOnline> list) {
        AgentOnline leastAgent = null;
        for (AgentOnline agentOnline : list) {
            if (leastAgent == null) {
                leastAgent = agentOnline;
            }
            if (leastAgent.getJobCount() > agentOnline.getJobCount()) {
                leastAgent = agentOnline;
            }
        }
        return leastAgent;
    }
}
